package com.jxc.jxc01.hch.dao.Impl;

import com.jxc.jxc01.hch.dao.LoginDao;
import com.jxc.jxc01.hch.entity.JDBCConn;
import com.jxc.jxc01.hch.entity.User;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LoginDaoImpl implements LoginDao {
    @Override
    public User logindao(String username, String password) {
       User user = new User();
        try {
            JDBCConn jdbcConn = new JDBCConn();
            String sql = "select * from user where username=? and password=?";
            PreparedStatement stat = jdbcConn.connect(sql);
            stat.setString(1,username);
            stat.setString(2,password);
            ResultSet rs = stat.executeQuery();
            if (rs.next()){
                user.setId(rs.getInt("id"));
                user.setDepartmentid(rs.getInt("departmentid"));
                user.setUsername(rs.getString("username"));
                user.setPassword(rs.getString("password"));
                user.setName(rs.getString("name"));
                user.setSex(rs.getString("sex"));
                user.setEmail(rs.getString("email"));
                user.setPhone(rs.getString("phone"));
                user.setState(rs.getString("state"));
                user.setCreationtime(rs.getString("Creationtime"));
                user.setAuthority(rs.getString("authority"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return user;
    }
}
